# coding:utf-8
from odoo import models, fields, api, _


class OLAccountInvoiceExtend(models.Model):
    _name = 'purchase.order'
    _inherit = 'purchase.order'

    vendor_payment_term_ids = fields.Many2many('account.payment.term', related='partner_id.vendor_payment_term_ids',
                                               readonly=True)

    @api.onchange('partner_id')
    def _onchange_partner_id(self):
        return {
            'domain': {'payment_term_id': [('id', 'in', self.vendor_payment_term_ids.ids)]},
        }


class PaulAccountInvoiceExtend(models.Model):
    _inherit = 'account.invoice'
    _name = 'account.invoice'

    vendor_payment_term_ids = fields.Many2many('account.payment.term', related='partner_id.vendor_payment_term_ids',
                                               readonly=True)

    @api.onchange('partner_id')
    def _onchange_invoice_partner_id(self):
        return {
            'domain': {'payment_term_id': [('id', 'in', self.vendor_payment_term_ids.ids)]},
        }
